<template>
  <!--  <j-modal-->
  <!--    :title="title"-->
  <!--    :width="1200"-->
  <!--    :visible="visible"-->
  <!--    :maskClosable="false"-->
  <!--    switchFullscreen-->
  <!--    :fullscreen=true-->
  <!--    @ok="handleOk"-->
  <!--    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"-->
  <!--    @cancel="handleCancel">-->
  <!--    <jzx-trade-form v-if="type!='2'" ref="realForm" :type="type" @ok="submitCallback"-->
  <!--                    :disabled="disableSubmit" />-->
  <!--    <jzx-trade-form-inside v-else ref="realForm" :type="type" @ok="submitCallback" :disabled="disableSubmit" />-->
  <!--  </j-modal>-->
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :destroy-on-close="true"
    :closable="true"
    :visible="visible"
    :get-container="false"
    :wrap-style="{ position: 'absolute' }"
    :keyboard="false"
    @close="close"
    destroyOnClose
  >
    <a-tabs :activeKey="activeKey" @change="callback">
      <a-tab-pane key="1" tab="基本信息" forceRender>
        <jzx-trade-form v-if="type!='2'" ref="realForm" :type="type" @ok="submitCallback"
                        :disabled="disableSubmit" />
        <jzx-trade-form-inside v-else ref="realForm" :type="type" @ok="submitCallback" :disabled="disableSubmit" />
      </a-tab-pane>
      <a-tab-pane key="2" tab="费用明细" forceRender>
        <expense-entry-form ref="expenseEntryForm"></expense-entry-form>
      </a-tab-pane>

    </a-tabs>

    <div style="margin-bottom: 50px;height: 10px"></div>

    <div v-show="!disableSubmit"
         :style="{
          position: 'absolute',
          right: 0,
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e9e9e9',
          padding: '10px 16px',
          background: '#fff',
          textAlign: 'right',
          zIndex: 999,
        }"
    >
      <a-button :style="{ marginRight: '8px' }" @click="handleCancel">
        关闭
      </a-button>
      <a-button v-if="activeKey == '1'?true:false" type="primary" @click="handleOk">
        保存
      </a-button>
    </div>
  </a-drawer>
</template>

<script>

import JzxTradeForm from './JzxTradeForm'
import JzxTradeFormInside from './JzxTradeFormInside'
import ExpenseEntryForm from './ExpenseEntryForm'

export default {
  name: 'JzxTradeModal',
  components: {
    JzxTradeForm,
    JzxTradeFormInside,
    ExpenseEntryForm
  },
  props: {
    type: {
      type: String,
      required: true,
      default: '1'
    }
  },
  data() {
    return {
      activeKey: '1',
      title: '',
      width: '95%',
      visible: false,
      disableSubmit: false,
      tableStatus: 0,
      recordid: ''
    }
  },
  mounted() {

  },
  methods: {
    callback(key) {
      console.log(key)
      this.activeKey = key
      if (key == '2') {
        this.$nextTick(() => {
          this.$refs.expenseEntryForm.setId(this.recordid)
          // this.$refs.expenseEntryForm.edit(record)
        })
      }

    },
    add() {
      this.activeKey = '1'
      this.recordid = ''
      console.log(this.type)
      this.visible = true
      this.tableStatus = 1
      this.$nextTick(() => {
        this.$refs.realForm.add()
      })
    },
    edit(record) {
      this.activeKey = '1'
      console.log(record.status)
      if (record.status == 1) {
        this.tableStatus = 2
      } else {
        this.tableStatus = 3
      }
      this.visible = true
      this.recordid = record.id
      this.$nextTick(() => {
        this.$refs.realForm.edit(record)
      })

    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      console.log('enter')
      console.log(this.type)
      console.log(this.tableStatus)
      // if (this.type != 2) {
      // if (this.tableStatus == 1) {
      this.$refs.realForm.save()
      // } else if (this.tableStatus == 2) {
      //   this.$refs.realForm.save()
      // } else if (this.tableStatus == 3) {
      //   this.$refs.realForm.handleOk()
      // }
      // } else {
      //   this.$refs.realForm.handleOk()
      // }

    },
    submitCallback(val) {
      this.recordid = val
      // this.$emit('ok')
      // this.visible = false
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>

<style scoped>
/deep/ .ant-drawer-body {
  padding: 0 0 0 5px;
}
</style>